package util;

public class Vector2D {

	public static final Vector2D ZERO_VECTOR = new Vector2D(0, 0);

	private final float x;
	private final float y;

	public Vector2D(float x, float y) {
		this.x = x;
		this.y = y;
	}

	public Vector2D scale(float k) {
		return new Vector2D(k * x, k * y);
	}

	public Vector2D invert() {
		return new Vector2D(-x, -y);
	}

	public Vector2D add(Vector2D v) {
		return new Vector2D(x + v.x, y + v.y);
	}

	public Vector2D subtract(Vector2D v) {
		return new Vector2D(x - v.x, y - v.y);
	}

	public float getLength() {
		return (float) Math.sqrt(x * x + y * y);
	}

	public Vector2D getUnitVector() {
		return new Vector2D(x / getLength(), y / getLength());
	}

	public Vector2D rotate(float alpha) {
		float sin = (float) Math.sin(Math.toRadians(alpha));
		float cos = (float) Math.cos(Math.toRadians(alpha));
		
		return new Vector2D(x * cos - y * sin, x
				* sin + y * cos);
	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}
}
